namespace("jswing.models.Resource", {
	'@inherits' : jswing.models.ComponentModel,
	'@traits'   : {http:DOMAssistant.AJAX},
	
	preInitialize: function(resourceDesc) {
		this.parent(arguments);
		this.start = this.start.bind(this,resourceDesc);
		return this;
	},
	
	resetModel : function(){
		this.model = {};
	},
	
	start : function(resourceDesc){
	},
	
	POST : function(obj, options) {
		//usage:  partners.POST({params:partner, url:"/some/location", callback:callback});
		if(!this.url) logger.error("Error occured while trying to post an \
		instance of the resource " + this.classname + ". Unable to find a 'url' property")
		
		var ajaxoptions = {
			url : (options.url && options.url.indexOf("/")==0) ? options.url:this.url,
			method : "POST",
			callback : options.callback||function(){},
			params : JSON.stringify(obj),
			headers : options.headers||{},
			responseType : options.responseType||"json",
			contentType  : options.contentType ||"application/json"};
//			ajaxoptions.url = ajaxoptions.url + "." + ajaxoptions.responseType || this.getDefaultContentType();
		return this.http.makeCall(ajaxoptions);
	},
	
	GET : function(obj, options){
		if(!this.url) logger.error("Error occured while trying to post an \
		instance of the resource " + this.classname + ". Unable to find a 'url' property")
		
		var ajaxoptions = {
			url :(options.url && options.url.indexOf("/")==0) ? options.url:this.url,
			method : "GET",
			callback : options.callback||function(){},
			params : JSON.stringify(obj||{}),
			headers : options.headers||{},
			responseType : options.responseType||"json",
			contentType  : options.contentType ||"application/json" };
//			ajaxoptions.url = ajaxoptions.url + "." + ajaxoptions.responseType || this.getDefaultContentType();
		return this.http.makeCall(ajaxoptions);
	},
	
	PUT : function(obj, options){
		if(!this.url) logger.error("Error occured while trying to post an \
		instance of the resource " + this.classname + ". Unable to find a 'url' property")
		
		var ajaxoptions = {
			url 		 : ((options.url && options.url.indexOf("/")==0) ? options.url:this.url),
			method 		 : "PUT",
			callback 	 : (options.callback||function(){}),
			params 		 : (typeof obj ==="object")?JSON.stringify(obj):obj,
			headers 	 : options.headers||{},
			responseType : options.responseType||"json",
			contentType  : options.contentType||"application/json"
		};
		return this.http.makeCall(ajaxoptions);
	},
	
	DELETE : function(obj, options){
		if(!this.url) logger.error("Error occured while trying to post an \
		instance of the resource " + this.classname + ". Unable to find a 'url' property")
		
		var ajaxoptions = {
			url : ((options.url && options.url.indexOf("/")==0) ? options.url:this.url),
			method : "DELETE",
			callback : options.callback||function(){},
			params : (typeof obj ==="object")?JSON.stringify(obj):obj,
			headers : options.headers||{},
			responseType : options.responseType||"json",
			contentType  : options.contentType ||"application/json"};
		return this.http.makeCall(ajaxoptions);
	},
	
	getDefaultContentType: function(){
		return "json";
	}
});
